package study.chapter03.thread.keywords;

//关键字volatile的使用
public class TestThread {
    public static void main(String[] args) {
//        MyThread myThread = new MyThread();
//        new Thread(myThread, "售票员A").start();
//        new Thread(myThread, "售票员B").start();
//        new Thread(myThread, "售票员C").start();

    }
}

class MyThread implements Runnable{
    public volatile int ticket = 5;

    @Override
    public void run() {
        synchronized (this){
            while (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "卖票：ticket=" + ticket--);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
